<?php

$order = $_SESSION['paging'][$path_string]['order'];
$filter = isset($_SESSION['paging'][$path_string]['filter']) ? '%' . $_SESSION['paging'][$path_string]['filter'] . '%' : '%';

$users = $db->fetchAll(
	$db->select()
	   ->from(array('u' => 'cms_users'))
	   ->order($order)
	   ->where($db->quoteInto('site_id=?', $site['id']))
	   ->where($db->quoteInto('id LIKE ? OR username LIKE ? OR email LIKE ? OR last_name LIKE ? OR first_name LIKE ?', $filter))
);

$page   = $_SESSION['paging'][$path_string]['page'];
$show   = $_SESSION['paging'][$path_string]['show'];
$offset = ($page - 1) * $show;
$total  = count($users);

$smarty->assign('order', $order);
$smarty->assign('page', $page);
$smarty->assign('show', $show);
$smarty->assign('filter', $filter);
$smarty->assign('offset', $offset);
$smarty->assign('total', $total);

$smarty->assign('users', array_slice($users, $offset, $show));

if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
	header('Content-type: text/xml');
	$smarty->display('global/users/index.tpl.taconite');
} else {
	$smarty->display('global/users/index.tpl.html');
}